package pqsk.android.audio.Models;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Broadcaster extends Thread
{
	private static final int IPORT = 8080;
	private ServerSocket server;
	private Socket socket;
	public Broadcaster() throws IOException
	{
		this(Broadcaster.IPORT);
		
	}
	public Broadcaster(int iPort) throws IOException
	{
		this.server = new ServerSocket(iPort);
		this.server.setReuseAddress(false);
		super.start();
	}
	
	@Override
	public void run()
    {
        try
        {
            while ( true )
            {
                //System.out.println("Server message: Waiting...");
                this.socket = server.accept();
                new BroadcasterService(this.socket).start();
            } // end while
        }
        catch(IOException ex)
        {
            //System.out.println("Server message: " + ex.getMessage());
        }
        finally
        {
            try
            {
                this.socket.close();
            }
            catch(IOException ex)
            {
                //System.out.println("Server message: " + ex.getMessage());
            }
        }

    } //run
}
